﻿using UnityEngine;
using UnityEngine.UI;
using ProtoBuf.Message;

namespace AutoChess
{
    public class ChessFightRecordPlayerInfo : MonoBehaviour
    {
        [SerializeField]
        private TextureKit mHeadIcon;
        [SerializeField]
        private Text mPlayerName;
        [SerializeField]
        private Text mPlayerServer;
        [SerializeField]
        private Text mRemainHero;
        [SerializeField]
        private Text mRemainHeroNum;
        [SerializeField]
        private GameObject mWinIcon;
        [SerializeField]
        private GameObject mLoseIcon;

        public void Init(AutoChessFightRecordPlayerInfo recordPlayerInfo, bool isLeft)
        {
            if (recordPlayerInfo.information != null)
            {
                mHeadIcon.textureType = TextureKit.TextureType.SHIP;
                string icon = UtilityHelper.GetShipIcon(recordPlayerInfo.shipId);
                if (string.IsNullOrEmpty(icon))
                {
                    ExLog.LogError("船Icon IsNullOrEmpty,服务器数据shipId:" + recordPlayerInfo.shipId);
                }
                else
                {
                    mHeadIcon.TextureName = UtilityHelper.GetShipIcon(recordPlayerInfo.shipId);
                }
                mPlayerName.text = recordPlayerInfo.information.nickName;
                mPlayerServer.enabled = false;
                //if (isLeft)
                //{
                //    mPlayerServer.text = "-" + string.Format(TableTextBlo.GetText("part_server"), recordPlayerInfo.information.serverId);
                //}
                //else
                //{
                //    mPlayerServer.text = string.Format(TableTextBlo.GetText("part_server"), recordPlayerInfo.information.serverId) + "-";
                //}
            }
            else
            {
                ExLog.LogError("自走棋战斗回放，服务器返回角色信息为空");
            }

            mRemainHero.text = TableTextBlo.GetText("Chess_HeroNumber");
            mRemainHeroNum.text = recordPlayerInfo.remainHeroNum.ToString();
            mWinIcon.SetActive(recordPlayerInfo.isWin);
            mLoseIcon.SetActive(!recordPlayerInfo.isWin);
        }
    }
}